# LuckPay Web Manage System
#
# Copyright (c) 2016 Lucky Byte, Inc.
#
$ ->
    form = $('form.main')
    form.form
        inline: true,
        fields:
            t40_amt:    optional: false, rules: [
                { type: 'empty' }, { type: 'regExp[/^-?[0-9,.]+$/]' }
            ]
            pay_chnl:   optional: false, rules: [ type: 'empty' ]
            pay_merid:  optional: false, rules: [ type: 'empty' ]
            acct_no:    optional: false, rules: [ type: 'empty' ]
            retrefno:   optional: false, rules: [
                { type: 'maxLength[12]' }, { type: 'minLength[12]' }
            ]

    if form.attr('action').endsWith 'check'
        $('body').css('background-color', 'black')

    # 处理确认按钮
    form.find('button#ok').click ->
        return if not form.form 'is valid'
        if $(this).hasClass 'clicked'
            $(this).removeClass('clicked red').addClass('green').text '确 定'
            form.submit()
        else
            $(this).removeClass('green').addClass('clicked red').text '确认追付'
